package com.gosophia.conference.action.notification;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.security.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;

import com.gosophia.commons.web.action.BaseSupportAction;
import com.gosophia.commons.web.logAnnotation.LogRecord;
import com.gosophia.conferenceManagement.ConferenceTurningAction;
import com.gosophia.conferenceManagement.notification.dto.NotificationJobDataDTO;
import com.gosophia.conferenceManagement.notification.ws.NotificationWebService;
import com.gosophia.oa.action.JudgeCurrentUndertaker;
import com.gosophia.springsecurity.UserDetailsImpl;
import com.opensymphony.xwork2.ActionContext;
/**
 * 会议通知修改Action
 * @author gaoweiguang
 * @since  2011-3-26
 *  Copyright (c) 2010 Gosophia corporation All Rights Reserved
 */
@Scope("prototype")
@Controller("ModifyNotificationApproveAction")
public class ModifyNotificationApproveAction  extends BaseSupportAction{

	private static final long serialVersionUID = -997340796023085481L;
	
	@Autowired
	private NotificationWebService notificationWebService;

	@Autowired
	private JudgeCurrentUndertaker judgeCurrentUndertaker;

	private NotificationJobDataDTO notificationJobDataDTO;

    private String notificationType;
    
    private Long jobId;
    @LogRecord(eventAction = "会议置办-会议通知修改", eventTarget = "notificationJobDataDTO")
	@Override
	public String _execute() throws Exception {
    	 //判断是否匹配,如果不匹配转到异常页面
        judgeCurrentUndertaker.judgeOperationAuthority(jobId);
		UserDetailsImpl userDetails = (UserDetailsImpl) SecurityContextHolder
        .getContext().getAuthentication().getPrincipal();
		Long userInfoId = userDetails.getUserAccountDTO().getUserInfoDTO().getUserInfoId();
		notificationJobDataDTO.setNotificationType(notificationType);
		notificationJobDataDTO.setTurningAction(ConferenceTurningAction.MODIFY_SUBMIT_APPROVAL.getValue());
		notificationWebService.HandleConferenceTurning(jobId, userInfoId, notificationJobDataDTO);
	    super.getRequestResult().setRsltCode("0");
		if("0".equals(notificationType)) {
		   super.getRequestResult().setMessage("会议预通知修改并提交下一个人审批");
	    } else if("1".equals(notificationType)) {
		  super.getRequestResult().setMessage("会议正式通知修改并提交下一个人审批");
	     }
		ActionContext.getContext().getSession().put("_lastOpResult", super.getRequestResult());
		if("task".equals(this.getFromFlag())){
			return "TASK";
		}
		return SUCCESS;
	}
	public NotificationJobDataDTO getNotificationJobDataDTO() {
		return notificationJobDataDTO;
	}
	public void setNotificationJobDataDTO(
			NotificationJobDataDTO notificationJobDataDTO) {
		this.notificationJobDataDTO = notificationJobDataDTO;
	}
	public String getNotificationType() {
		return notificationType;
	}
	public void setNotificationType(String notificationType) {
		this.notificationType = notificationType;
	}
	public Long getJobId() {
		return jobId;
	}
	public void setJobId(Long jobId) {
		this.jobId = jobId;
	}
	
	

}
